package com.chenfan.mcn.enums;

import java.util.Objects;

/**
 * @Author liuyang
 * @Date 2021/3/3
 * @Time 11:33
 * @Version V1.0
 **/
public enum AnnualRebateApprovalEnum {

    /**
     * 年度折扣审批单 状态
     */
    UN_COMMIT(0, "待提交"),

    APPROVAL(1, "审批中"),

    REJECTED(2, "审批拒绝"),

    CANCEL(3, "已撤回"),

    WAITING_PAYMENT(4, "待打款"),

    PAID(5, "已打款"),

    INVALID(9, "已作废");

    private final int code;
    private final String statusName;

    AnnualRebateApprovalEnum(int code, String statusName) {
        this.code = code;
        this.statusName = statusName;
    }

    public int code() {
        return this.code;
    }

    public static String getStatusName(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        for (AnnualRebateApprovalEnum status : AnnualRebateApprovalEnum.values()) {
            if (status.code == code.intValue()) {
                return status.statusName;
            }
        }
        return null;
    }

    public static boolean isApproval(Integer code) {
        return Objects.nonNull(code) && AnnualRebateApprovalEnum.APPROVAL.code == code.intValue();
    }

    public static boolean isInvalid(Integer code) {
        return Objects.nonNull(code) && AnnualRebateApprovalEnum.INVALID.code == code.intValue();
    }

    /** 根据状态码任意匹配
     * @param code
     * @param items
     * @return
     */
    public static boolean anyMatch(Integer code, AnnualRebateApprovalEnum... items) {
        boolean match = false;
        if(code != null) {
            for(AnnualRebateApprovalEnum item : items) {
                if(item.code() == code.intValue()) {
                    match = true;
                    break;
                }
            }
        }
        return match;
    }
}
